<script setup lang="ts">
import { homerecommed } from '../../api/home'
import { ref } from "vue"
import { type Data, type Item } from '@/typings'

const total = ref<Array<Data>>([])

const banners = ref<Array<Item>>([])
const tabs = ref<Array<Item>>([])
const showPhone = ref<Array<Item>>([])
const itemS = ref<Array<Item>>([])
const itemS1 = ref<Array<Item>>([])
const itemS2 = ref<Array<Item>>([])
const morePhone = ref<Array<Item>>([])
const watchTv = ref<Array<Item>>([])
const moreTv = ref<Array<Item>>([])
const maxComputer = ref<Array<Item>>([])
const moreComputer = ref<Array<Item>>([])
const moreComputerS = ref<Array<Item>>([])
const Jiadian = ref<Array<Item>>([])
const moreJd = ref<Array<Item>>([])
const moreZN = ref<Array<Item>>([])
const Zn1 = ref<Array<Item>>([])
const Zn2 = ref<Array<Item>>([])
const Zn3 = ref<Array<Item>>([])
import { useRouter } from 'vue-router';


const router = useRouter()
const goLookMore = (id: number) => {
    router.push({
        name: 'look',
        params: {
            id: id
        }
    })
}


const getCt = async () => {
    let data = await homerecommed()
    total.value = data
    // console.log(data);
    banners.value = data[0].body.items
    tabs.value = data[1].body.items.concat(data[2].body.items)
    showPhone.value = data[4].body.items
    itemS.value = data[6].body.items
    itemS1.value = data[8].body.items
    itemS2.value = data[10].body.items
    morePhone.value = data[12].body.items
    watchTv.value = data[14].body.items
    moreTv.value = data[16].body.items
    maxComputer.value = data[18].body.items
    moreComputer.value = data[20].body.items
    moreComputerS.value = data[22].body.items
    Jiadian.value = data[24].body.items
    moreJd.value = data[25].body.items
    moreZN.value = data[27].body.items
    Zn1.value = data[29].body.items
    Zn2.value = data[31].body.items
    Zn3.value = data[33].body.items
}
getCt()





</script>
<template>
    <div class="swiper">
        <el-carousel :interval="5000" arrow="always" height="200px" indicator-position="none">
            <el-carousel-item v-for="item in banners" :key="item.material_id">
                <img :src='`https:${item.img_url}`'>
            </el-carousel-item>
        </el-carousel>
    </div>
    <div class="tabs">
        <div class="item" v-for="item in tabs" :key="item.material_id">
            <img :src='`https:${item.img_url}`'>
        </div>
    </div>
    <div class="showPhoneBox">
        <div class="showPhone">
            <div class="left" v-for="item in showPhone.slice(0, 1)" :key="item.product_id">
                <img :src='`https:${item.img_url}`'>
            </div>
            <div class="right">
                <img v-for="item in showPhone.slice(1)" :key="item.product_id" :src='`https:${item.img_url}`'>
            </div>
        </div>
        <div class="itemPhone">
            <div class="phone" v-for=" item in itemS" :key="item.product_id">
                <router-link :to="{ name: 'info', params: { id: item.product_id } }">
                    <img :src='`https:${item.img_url}`'></router-link>



                <div class="title">
                    <h3 class="name"> {{ item.product_name }}</h3>
                    <p class="info"> {{ item.product_brief }}</p>
                    <div class="price">￥ {{ item.product_price }}起</div>
                </div>
                <div class="btn"><span>立即购买</span></div>
            </div>
        </div>
        <div class="itemPhone">
            <div class="phone" v-for=" item in itemS1" :key="item.product_id">
                <router-link :to="{ name: 'info', params: { id: item.product_id } }">
                    <img :src='`https:${item.img_url}`'></router-link>
                <div class="title">
                    <h3 class="name"> {{ item.product_name }}</h3>
                    <p class="info"> {{ item.product_brief }}</p>
                    <div class="price">￥ {{ item.product_price }}起</div>
                </div>
                <div class="btn"><span>立即购买</span></div>
            </div>
        </div>
        <div class="itemPhone">
            <div class="phone" v-for=" item in itemS2" :key="item.product_id">
                <router-link :to="{ name: 'info', params: { id: item.product_id } }">
                    <img :src='`https:${item.img_url}`'></router-link>
                <div class="title">
                    <h3 class="name"> {{ item.product_name }}</h3>
                    <p class="info"> {{ item.product_brief }}</p>
                    <div class="price">￥ {{ item.product_price }}起</div>
                </div>
                <div class="btn"><span>立即购买</span></div>
            </div>
        </div>
        <div class="lookMore">
            <p v-for="item in morePhone" :key="item.action.path" @click="goLookMore(item.action.path)">{{ item.action_title
            }}></p>
        </div>
    </div>
    <div class="showTvBox">
        <div class="pic" v-for="item in watchTv" :key="item.material_id">
            
            <img :src='`https:${item.img_url}`' alt="">
        </div>
        <div class="lookMore">
            <p v-for="item in moreTv " :key="item.action.path" @click="goLookMore(item.action.path)">{{ item.action_title
            }}></p>
        </div>
    </div>
    <div class="showComputerBox">
        <div class="maxComputer">
            <img v-for="item in maxComputer" :key="item.material_id" :src="item.img_url" alt="">
        </div>
        <div class="itemComputer">
            <div class="computer" v-for=" item in moreComputer" :key="item.product_id">
                <router-link :to="{ name: 'info', params: { id: item.product_id } }">
                    <img :src='`https:${item.img_url}`'></router-link>
                <div class="title">
                    <h3 class="name"> {{ item.product_name }}</h3>
                    <p class="info"> {{ item.product_brief }}</p>
                    <div class="price">￥ {{ item.product_price }}起</div>
                </div>
                <div class="btn"><span>立即购买</span></div>
            </div>
        </div>
        <div class="lookMore">
            <p v-for="item in moreComputerS" :key="item.action.path" @click="goLookMore(item.action.path)">{{
                item.action_title }}></p>
        </div>
    </div>
    <div class="showJiaDianBox">
        <div class="pic" v-for="item in Jiadian" :key="item.material_id">
            <img :src='`https:${item.img_url}`' alt="">


        </div>
        <div class="lookMore">
            <p v-for="item in moreJd " :key="item.action.path" @click="goLookMore(item.action.path)">{{ item.action_title
            }}></p>
        </div>
    </div>
    <div class="showZnBox">
        <div class="lookMore">
            <p v-for="item in moreZN " :key="item.action.path" @click="goLookMore(item.action.path)">{{ item.action_title
            }}></p>
        </div>
        <div class="ZnBox">
            <div class="Zn" v-for=" item in Zn1" :key="item.product_id">
                <img :src='`https:${item.img_url}`'>
            </div>

        </div>
        <div class="ZnBox">
            <div class="Zn" v-for=" item in Zn2" :key="item.product_id">
                <img :src='`https:${item.img_url}`'>
            </div>

        </div>
        <div class="ZnBox">
            <div class="Zn" v-for=" item in Zn3" :key="item.product_id">
                <img :src='`https:${item.img_url}`'>
            </div>

        </div>
    </div>
</template>

<style scoped>
.showPhoneBox,
.showTvBox,
.showComputerBox,
.showJiaDianBox,
.showZnBox {
    margin-top: 5px;
}

img {
    width: 100%;
    vertical-align: middle;
}

.swiper {
    margin-top: 5px;
}

.el-carousel__item img {
    width: 100%;
    height: 100%;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
    background-color: #d3dce6;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
}

.item {
    width: 78px;
    height: 80px;

}


.showPhone {
    width: 100vw;
    height: 275px;
    overflow: hidden;
    background-color: #ffffff;


}

.right {
    width: 49vw;
    height: 275px;
    float: right;
    display: flex;
    flex-wrap: wrap;
}

.left {
    width: 49vw;
    float: left;
}



.right img {
    width: 100%;
    height: 49%;
    margin-top: 1px;
}

.itemPhone,
.itemComputer {
    display: flex;
    justify-content: space-evenly;
    background-color: #ffffff;

}

.phone,
.computer {
    width: 45vw;
    margin-top: 10px;

}


.phone .title,
.computer .title {
    text-align: center;
    min-width: 150px;
}

.phone .title .name,
.computer .title .name {
    font-size: 14px;
    font-family: "宋体";
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    overflow: hidden;
}

.phone .title .info,
.computer .title .info {
    width: 180px;
    padding: 0 20px;
    box-sizing: border-box;
    font-size: 12px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    overflow: hidden;

}

.phone .title .price,
.computer .title .price {
    color: #ea625b;
}

.phone .btn,
.computer .btn {
    background-color: #ea625b;
    text-align: center;
    width: 108px;
    height: 32px;
    padding: 0 8.6px;
    line-height: 32px;
    color: #fff;
    margin: 0 auto;
    border-radius: 5px;
}

.lookMore p {
    text-align: center;
    background-color: #ffffff;
    margin: 0;
    height: 30px;
    line-height: 30px;
    font-size: 18px;
    padding: 10px 0;
}

.showTvBox .pic {
    width: 100vw;
    margin-top: 10px;
}

.showZnBox {
    margin-bottom: 56px;
}

.ZnBox {
    display: flex;
    justify-content: space-evenly;
    margin-top: 5px;


}

.ZnBox .Zn {
    width: 48vw;
}
</style>